package cn.rongdao.jrkabao.util.moxie;

import com.mifengkong.frtools.http.request.callback.BaseImpl;
import com.mifengkong.frtools.http.request.callback.FRBaseObserver;
import com.mifengkong.frtools.util.FRString;
import com.moxie.client.model.MxParam;

import cn.mifengkong.appcommon.moxie.FRMoXieManager;
import cn.rongdao.jrkabao.model.SendVerificateTypeToServerModel;
import cn.rongdao.jrkabao.util.GetDefaultDataUtil;

/**
 * Created by jack on 2017/12/12
 */

public class MoXieManager extends FRMoXieManager {

    private BaseImpl baseImpl;

    private OnMoXieReturnListener onMoXieReturnListener;

    public MoXieManager(final BaseImpl baseImpl) {
        super(baseImpl.getActivity());
        this.baseImpl = baseImpl;
    }

    public void initKaMaoMoXie(){
        initMoXie(MxParam.PARAM_TASK_EMAIL, GetDefaultDataUtil.getMoXieContent(baseImpl.getActivity()));
    }

    public void initMoXieContent(String function) {
        initMoXie(function, GetDefaultDataUtil.getMoXieContent(baseImpl.getActivity()));
    }

    public void initOnlineBankingMoXieContent(String function) {
        initOnlineBankingMoXie(function, GetDefaultDataUtil.getMoXieContent(baseImpl.getActivity()));
    }

    private void sendVerifyCateType2Server(String materialCode) {
        SendVerificateTypeToServerModel.getInstance().execute(materialCode, new FRBaseObserver<String>(baseImpl) {
            @Override
            protected void onBaseNext(String data) {
            }

            @Override
            protected void onBaseError(Throwable t) {
                handingExceptions(t, false);
            }
        });
    }

    public void startMoXieWithEmail() {
        startMoXieWithEmail("");
    }

    public void startMoXieWithMxParam(MxParam mxParam) {
        if (null==mxParam){
            startMoxieActivity();
        }else {
            startMoxieActivity(mxParam);
        }
    }

    public void startMoXieWithEmail(String jumpEmail) {
        if (!FRString.isEmpty(jumpEmail)) {   //魔蝎某个邮箱
            setEmailLoginInfo(jumpEmail);
        } else {
            initKaMaoMoXie();
        }
        startMoxieActivity();
    }

    @Override
    protected void looperMethod(String email) {
        if (null != onMoXieReturnListener) {
            onMoXieReturnListener.looperMethod(email);
        }
    }

    @Override
    protected void successReturn(String email) {
        if (null != onMoXieReturnListener) {
            onMoXieReturnListener.successReturn(email);
        }
    }

    @Override
    protected void verifyCate(String materialCode) {
        sendVerifyCateType2Server(materialCode);
    }

    public interface OnMoXieReturnListener {
        void looperMethod(String email);

        void successReturn(String email);
    }

    public void setOnMoXieReturnListener(OnMoXieReturnListener onMoXieReturnListener) {
        this.onMoXieReturnListener = onMoXieReturnListener;
    }
}